package app.mvc.model.keyboards
{
	import alternativa.gui.keyboard.IKeyFilter;
	
	import app.mvc.Notifications;
	
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	import org.puremvc.as3.patterns.facade.Facade;
	
	public class AppMainLayerKeyFilter implements IKeyFilter
	{
		private var _keyCode:int=0;
		
		public function AppMainLayerKeyFilter()
		{
		}

		/**
		 * 键盘按下事件
		 */
		public function onKeyDown(...rest):void
		{
			switch(_keyCode)
			{
				case Keyboard.Z:
					if(_keyCode)		//ctrl+z 撤销
					{
						Facade.getInstance().sendNotification(Notifications.CMD_TO_UNDO);
					}
					break;
				case Keyboard.Y:
					if(_keyCode)		//ctrl+y 还原
					{
						Facade.getInstance().sendNotification(Notifications.CMD_TO_REDO);
					}
					break;
			}
		}
		
		public function filter(e:KeyboardEvent):Boolean
		{
			_keyCode = e.keyCode;
			switch(e.keyCode)
			{
				case Keyboard.Z:
					if(e.ctrlKey)
						return true;
					break;
				case Keyboard.Y:
					if(e.ctrlKey)
						return true;
					break;
			}	

			return false;
		}
		
		public function get keyCode():Array
		{
			return [_keyCode];
		}
	}
}